package patterns.memento;

/**
 * Created by lenovo on 2016/12/1 0001.
 * 演示操作备忘录模式，使用caretaker和originator类对象。
 */
public class MementoPatternDemo {
    public static  void main(String[] args){
        Originator originator = new Originator();
        CareTaker careTaker = new CareTaker();
        //初始化状态
        originator.setState("State #1");
        //状态这次被保存
        originator.setState("State #2");
        careTaker.add(originator.saveStateToMemento());
        //又被保存了一次状态
        originator.setState("State #3");
        careTaker.add(originator.saveStateToMemento());
        //最新状态
        originator.setState("State #4");

        //看看状态效果，以及恢复状态试试
        System.out.println("当前状态是： "+ originator.getState());
        originator.getStateFromMemento(careTaker.get(0));
        System.out.println("第一次保存的状态是： "+ originator.getState());
        originator.getStateFromMemento(careTaker.get(1));
        System.out.println("第二次保存的状态是： "+ originator.getState());
    }
}
